//
//  HMStatusTransmitView.swift
//  01-SinaWeibo
//
//  Created by 周英培 on 16/5/25.
//  Copyright © 2016年 周英培. All rights reserved.
//  微博转发视图

import UIKit

import SnapKit

class HMStatusTransmitView: UIView {
    
   //设置约束对象属性
    var bottomCons : Constraint?
    
    
    
    //赋值数据
    var statusViewModel: HMStatusViewModel? {
    
        didSet {
        
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            
//            transMitPictureView.pictures = statusViewModel?.status?.retweeted_status?.pic_urls
            
            //卸载约束
            bottomCons?.uninstall()
            //根据是否有转发微博视图 来设置底部约束
            if let urls = statusViewModel?.status?.retweeted_status?.pic_urls {
                //有转发微博视图
                //设置数据
                transMitPictureView.pictures = urls
                
                //显示视图
                transMitPictureView.hidden = false
                
                //设置约束
//                self.snp_makeConstraints(closure: { (make) in
//                    self.bottomCons = make.bottom.equalTo(transMitPictureView).offset(margin).constraint
//                })
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomCons = make.bottom.equalTo(transMitPictureView).offset(margin).constraint
                })
            } else {
            
            //没有视图
                //隐藏
                transMitPictureView.hidden = true
                
                //设置约束
//                self.snp_makeConstraints(closure: { (make) in
//                    self.bottomCons = make.bottom.equalTo(contentLabel).offset(margin).constraint
//                })
                self.snp_updateConstraints(closure: { (make) in
                    self.bottomCons = make.bottom.equalTo(contentLabel).offset(margin).constraint
                })
            
            }
            
            
        
        }
    
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
         backgroundColor = UIColor(white: 0.95, alpha: 1)
        setUpUI()
        
    
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:懒加载
    private lazy var contentLabel : UILabel = UILabel(title: "情字何解，怎落笔都不对，而我独缺，你一生的 了解，我等春雷，来提醒你爱谁;我想大声宣布，对你依依不舍，我想就这样牵着你的手说不放开", font: 12, textColor: UIColor.darkGrayColor(),alignment:.Left)
    private lazy var transMitPictureView : HMStatusPickerView = HMStatusPickerView()
    
    //MARK:设置UI 设置约束
    private func setUpUI() {
    
       addSubview(contentLabel)
        addSubview(transMitPictureView)
        
        //转发微博里面的文字内容
       contentLabel.snp_makeConstraints { (make) in
        make.top.left.equalTo(self).offset(margin)
        }
        
        transMitPictureView.snp_makeConstraints { (make) in
            make.left.equalTo(contentLabel)
            make.top.equalTo(contentLabel.snp_bottom).offset(margin)
        }
        
        //给转发微博的底部设置约束
        self.snp_makeConstraints { (make) in
            
            //记录底部约束
           self.bottomCons = make.bottom.equalTo(transMitPictureView.snp_bottom).offset(margin).constraint
        }
    
    }
    
    
    

}
